package com.itheima.controller;

import com.itheima.pojo.Job;
import com.itheima.pojo.JobChange;
import com.itheima.pojo.Result;
import com.itheima.service.JobChangeService;
import com.itheima.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class JobChangeController {

    @Autowired
    private JobChangeService jobChangeService;
    //private static Logger log= LoggerFactory.getILogger(DeptController.class);
    // @RequestMapping(value = "/depts",method = )
    @GetMapping("/jobchanges")
    public Result list(){
        log.info("查询全部部门数据");
        List<JobChange> jobchangeList= jobChangeService.list();
        return Result.success(jobchangeList);
    }

    @PostMapping("/jobchanges")
    public Result add(@RequestBody JobChange jobChange){
        Integer a=jobChange.getEmpId();
        Integer b=jobChange.getJobId();
        Integer ret=jobChangeService.func(a,b);//更改员工表
        String name=jobChangeService.func4(ret);
        String name1=jobChangeService.func5(b);
        jobChangeService.func6(a,name1);//更改员工表
        String empname=jobChangeService.func7(a);
        jobChange.setEmpName(empname);
        jobChange.setJobName(name);
        jobChange.setJobName1(name1);
        jobChangeService.add(jobChange);
        jobChangeService.func3(ret,a);//添加原职位号
        return Result.success();
    }
//    @PutMapping("/deptchanges")
//    public Result update1(@RequestBody DeptChange deptChange){
//        log.info("修改部门为:{}",deptChange);
//        deptChangeService.update2(deptChange);
//        return Result.success();
//    }

}
